package cc.admin.modules.sys.service.impl;

import cc.admin.common.sys.vo.LoginUser;
import cc.admin.modules.sys.entity.MessageNotification;
import cc.admin.modules.sys.mapper.MessageNotificationMapper;
import cc.admin.modules.sys.service.IMessageNotificationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: cc-admin
 * @Date: 2023-02-23
 * @Version: V1.0.0
 */
@Service
public class MessageNotificationServiceImpl extends ServiceImpl<MessageNotificationMapper, MessageNotification> implements IMessageNotificationService {
    @Autowired
    private MessageNotificationMapper messageNotificationMapper;

    @Override
    public Boolean getMessageByCompanyId(MessageNotification messageNotification) {
		LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		QueryWrapper<MessageNotification> queryWrapper = new QueryWrapper<MessageNotification>();
        queryWrapper.eq("tenant_id", user.getTenantId());
        if (messageNotification.getId() != null) {
            queryWrapper.ne("id", messageNotification.getId());
        }
        List<MessageNotification> messageNotifications = messageNotificationMapper.selectList(queryWrapper);
        if (messageNotifications.size() > 0) {
            return false;
        }
        return true;
    }
}
